import dayjs from "dayjs";

export function formatDate(date: string | Date, format = "YYYY-MM-DD") {
    return dayjs(date).format(format);
}

export function formatDateTime(date: string | Date, format = "YYYY-MM-DD HH:mm:ss") {
    return formatDate(date, format);
}

export function formatDateTimeNotS(date: string, format = "YY-MM-DD HH") {
    const year = new Date().getFullYear().toString();
    // 若为今年
    if (date.slice(0, 4) === year) {
        format = "MM-DD HH";
    }
    return formatDate(date, format);
}


/**
 * 数组去重
 * @param {Array} arr 数组
 */
export function arrUnique(arr: any[]) {
    const list = [...arr]
    return list.reduce((mult, item) => {
        !mult.includes(item) ? mult.push(item) : null
        return mult
    }, [])
}